/**************************************************************************************************/
/*                                    Global Workings                                             */
/**************************************************************************************************/
world/hub = "mikau.saloon"
var
	version = "v0.05"

	/* Lists */
	MuteList = list()
	Banned = list()
	Admins = list("mikau","divinetraveller","deadstarr","evanx","audeuro","sinfall","stephen001","superantx")
	REBOOT = FALSE

	list/Available = list()
	list/Busy = list()
	list/Away = list()
	list/Idle = list()
	list/TelnetInfo = null

	/* Main Chat */
	Message = {"<center><b>Welcome to The Saloon.</b>[version]</center>

We've recently switched over the user controls to an interface instead of Javascript.
Please report any bugs you find with this, or anything else. We can't fix what you don't report.
The forum can be found <a href="http://www.byond.com/members/Mikau/forum?forum=25">here</a>.
As well, the hub entry <a href="http://www.byond.com/games/Mikau/Saloon">here</a>.

"}

	Bot_Color = "#083C76"
	ConversationTopic = "No topic"

	/* Lists */
	Pastebin/pastebin = new

proc
	TelnetInfo(client/C)
		if(!TelnetInfo || !C || (!istype(C) && !istext(C)) || (istype(C) && !(C.ckey in TelnetInfo)) || (istext(C) && !(C in TelnetInfo))) return null
		else return TelnetInfo[(istype(C) ? C.ckey : C)]
	TelnetAuth(uname, pwd)
		if(!uname || !pwd || !istext(uname) || !istext(pwd)) return 0
		var/list/L = TelnetInfo(uname)
		if(!L || pwd != L["pwd"]) return 0
		return list(L["uname"], L["cmd"])
	SetTelnetInfo(client/C, pass, cmd)
		if(!C || !istype(C) || !istext(pass) || !istext(cmd)) return null
		if(!TelnetInfo) TelnetInfo = new
		TelnetInfo[C.ckey] = list("pwd" = pass, "cmd" = cmd, "uname" = C.key)
	TelnetPass(client/C)
		if(!C || !istype(C)) return ""
		var/list/L = TelnetInfo(C)
		if(!L) return ""
		return L["pwd"]
	TelnetCmd(client/C)
		if(!C || !istype(C)) return ""
		var/list/L = TelnetInfo(C)
		if(!L) return ""
		return L["cmd"]
	findTarget(string)
		for(var/client/c)
			if(c.key == string || c.ckey==string)
				return c
		return null

	/* Saves the main lists */
	SaveTheWorld()
		fdel("Config.sav")
		var/savefile/F2 = new("Config.sav")
		F2["MuteList"]<<MuteList
		F2["Banned"]<<Banned
		F2["Admins"]<<Admins
		F2["TelnetInfo"]<<TelnetInfo

	/* Loads the main lists */
	LoadTheWorld()
		if(fexists("Config.sav"))
			var/savefile/F2 = new("Config.sav")
			F2["MuteList"]>>MuteList
			F2["Banned"]>>Banned
			F2["Admins"]>>Admins
			F2["TelnetInfo"]>>TelnetInfo

	/* Send a world message as the Wench */
	System_WorldMessage(message)
		world<<"<b>\[</b>[time2text(world.timeofday,"hh:mm:ss")]<b>\] <font color='[html_encode(Bot_Color)]'>@Wench</font></b>: <font color='red'>[message]</font>"

	/* Send a specific user a message as the Wench */
	System_UserMessage(Target, message)
		Target<<"<b>\[</b>[time2text(world.timeofday,"hh:mm:ss")]<b>\] <font color='[html_encode(Bot_Color)]'>@Wench</font></b>: <font color='red'>[message]</font>"

	BubbleSort(list/L)
		var/client/A
		var/client/B
		for(var/outer=1,outer<L.len,++outer)
			for(var/inner=L.len,inner>outer,--inner)
				A=L[inner]
				B=L[inner-1]
				if((A.key)<(B.key))
					L[inner]=B
					L[inner-1]=A

world
	name = "The Saloon"
	New()
		..()
		if(!WORKING) LoadTheWorld()

	Del()
		if(!WORKING) SaveTheWorld()
		Available.Cut()
		Busy.Cut()
		Away.Cut()
		Idle.Cut()
		..()

